<template>
<div>
  <dl @click="handlerProductDetails(product.product_id)">
    <dt>
      <span :class="{'red':product.collected == 1}" @click.stop="collectionPorduct(product.product_id,product.collected,product.collection_id)"><i class="iconfont icon-shoucang"></i></span>
      <img :src="product.product_cover+'?x-oss-process=image/resize,w_400,h_400/quality,Q_80/format,jpg'" mode="aspectFit"/>
    </dt>
    <dd>
      <p class="designerName">{{product.designer_name}}</p>
      <p class="productName">{{product.product_name}}</p>
      <p class="productpriceDellabel" v-show="product.line_price">
        <del v-if="product.line_price">{{product.currency_logo}}{{product.line_price}}</del>
        <font class="discount" v-if="product.label_text">{{product.label_text}}</font>
      </p>
      <p class="productprice" :style="{color: '#' + product.price_color}">
        <font class="showPrice">{{product.currency_logo}}{{product.show_price}}</font>
        <font class="calculationPrice" v-if="product.calculation_price_text">{{product.calculation_price_text}}</font>
      </p>
    </dd>
  </dl>
</div>
</template>

<script>
export default {
  props: ['product'],
  data() {
    return {
      
    };
  },
  methods: {
    handlerProductDetails(id){
      this.$wx.jumper('/pages/productDetails/main?productId=' + id)
    },
    collectionPorduct(id,iscollected,collectedId){
      const self = this
      if(this.$wx.isLogin()){
        if(iscollected == 0){
          this.getcollectionPorduct(id)
        } else{
          this.removeCollectionPorduct(id,collectedId)
        }
      } else{
        wx.showModal({
          title: '提示',
          content: '您还没有登录，去登录?',
          success(res) {
            self.$wx.jumper("../login/main");
          }
        })
      }
    },
    async getcollectionPorduct(id) {
      const data = await this.$fly.post(this.$url.URL_ADDCOLLECTIONPRODUCT, {
        product_id: id
      })
      if (data.successCode === 1) {
        this.$wx.showLongToast('收藏成功！')
        this.product.collected = 1
      }
    },
    async removeCollectionPorduct(id,collectedId) {
      const data = await this.$fly.post(this.$url.URL_REMOVECOLLECTIONPRODUCT, {
        collection_id: collectedId
      })
      if (data.successCode === 1) {
        this.$wx.showLongToast('取消成功！')
        this.product.collected = 0
      }
    },
  }
};
</script>
